﻿using System.Collections;
using System.Collections.Generic;
using FairyGUI;
using UnityEngine;

public class FTipPanelMediator : MyWindow
{
    GTextField _tipText;
    OneDelegate _callBack;
    GObject _submitBtn;
    GObject _cancelBtn;

    protected override void OnInit()
    {
 	    base.OnInit();
        this.contentPane = UIPackage.CreateObject("CommonPackage", "TipPanel").asCom;
        _tipText = this.contentPane.GetChild("text").asTextField;
        this.Center();//居中
        this.modal = true;

        this.contentPane.GetChild("closeBtn").onClick.Add(OnCloseBtn);
        _submitBtn = this.contentPane.GetChild("submitBtn");
        _cancelBtn = this.contentPane.GetChild("cancelBtn");
        _submitBtn.onClick.Add(OnSubmitBtn);
        _cancelBtn.onClick.Add(OnCloseBtn);
    }
        
	// Use this for initialization
    protected override void OnShown()
    {
 	    base.OnShown();
        this.Center();//居中
    }
    private void OnSubmitBtn(EventContext context)
    {
        if (_callBack != null) _callBack(1);
        this.Hide();
    }
    private void OnCloseBtn(EventContext context)
    {
        if (_callBack != null) _callBack(0);
        this.Hide();
    }
    public void Tip(string text,OneDelegate cb)
    {
        _callBack = cb;
        _tipText.text = text;

        //根据是否有回调函数，设置按钮的显隐
        if(_callBack == null) {
            _submitBtn.visible = false;
            _cancelBtn.visible = false;
        }
        else {
            _submitBtn.visible = true;
            _cancelBtn.visible = true;
        }
    }
}
